package jgl.vajra.kingkong.widget.loopviewpage;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.widget.giide.GlideImageLoader;

import java.lang.ref.WeakReference;
import java.util.List;


/**
 * @author ryze
 * @since 1.0  2016/07/17
 */
public class AutoSwitchStringDataAdapter extends AutoLoopSwitchBaseAdapter {

    private WeakReference<Context> mContext;

    private List<String> mDatas;

    public AutoSwitchStringDataAdapter() {
        super();
    }

    public AutoSwitchStringDataAdapter(Context mContext, List<String> mDatas) {
        this.mContext = new WeakReference<>(mContext);
        this.mDatas = mDatas;
    }

    @Override
    public int getDataCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public View getView(final int position) {

        ImageView imageView = new ImageView(mContext.get());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
        final String info = (String) getItem(position);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        // 展示数据
        GlideImageLoader.onDisplayRadius(imageView, info, R.dimen.dp_8);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return imageView;
    }


    @Override
    public Object getItem(int position) {
        if (position >= 0 && position < getDataCount()) {
            return mDatas.get(position);
        }
        return null;
    }


    @Override
    public View getEmptyView() {
        return null;
    }

    @Override
    public void updateView(View view, int position) {

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
